﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Data.OracleClient;

namespace UFC.Common
{
    public class LogHelp
    {
        public static ILog loginfo = log4net.LogManager.GetLogger("loginfo");
        public static ILog logerror = log4net.LogManager.GetLogger("logerror");
        private static ILog myLog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public static ILog logoracle = log4net.LogManager.GetLogger("logoracle");//add:Wangjh 2017-9-13

        public static void SetConfig()
        {
            log4net.Config.XmlConfigurator.Configure();
        }

        public static void WriteLog(string strInfo)
        {
            loginfo.Info(strInfo);
        }

        public static void WriteError(string strInfo, Exception e)
        {
            logerror.Error(strInfo, e);
        }
        /// <summary>
        /// 转化传参的sql
        /// add:Wangjh 20180713 
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="para"></param>
        /// <returns></returns>
        public static string TranferSql(String strSql, OracleParameter[] para)
        {
            foreach (OracleParameter eachPara in para)
            {
                strSql = strSql.Replace(eachPara.ParameterName, "'" + eachPara.Value.ToString() + "'");
            }
            return strSql;
        }

        /// <summary>
        /// 日志写入到数据库
        /// create:Wangjh 2017-9-13
        /// </summary>
        /// <param name="strInfo"></param>
        /// <param name="args"></param>
        public static void WriteOrcale(string strInfo, params object[] args)
        {
            logoracle.InfoFormat(strInfo, args);
        }
        /// <summary>
        /// 错误信息日志写入到数据库
        /// create:Wangjh 2017-9-13
        /// </summary>
        /// <param name="strInfo"></param>
        /// <param name="args"></param>
        public static void WriteOrcaleError(string strInfo, params object[] args)
        {
            logoracle.ErrorFormat(strInfo, args);
        }

    }
}
